package com.bizfx.component.controls
{
	import com.bizfx.utils.StringUtils;
	import com.bizfx.component.FieldDataType;
	
	[Bindable]
	public class QueryCondition
	{
		private var _queryLogic:String;
		
		public function get queryLogic():String {
			return _queryLogic;
		}
		
		public function set queryLogic(value: String):void {
			_queryLogic = value;
		}
		
		private var field:SearchField;

		public function get fieldName():String {
			return field.dataField;
		}
		
		private var operator:Object;
		
		public function get queryOperator():String {
			return operator.data;
		}
		
		private var _fieldValueString: String;
		
		public function get fieldValueString():String {
			return _fieldValueString;
		}
		
		private var _fieldType:String = FieldDataType.STRING;
		
		public function get fieldType(): String
		{
			return _fieldType;
		}
		
		public function set fieldType(value: String):void
		{
			_fieldType = value;
		}
		
		public function QueryCondition(queryLogic:String, field:SearchField, queryOperator:Object, fieldValue:String)
		{
			this._queryLogic = queryLogic;
			this.field = field;
			this.operator = queryOperator;
			this._fieldValueString = fieldValue;
			this._fieldType = field.fieldType;
		}
		
		public function get conditionString(): String{
			return StringUtils.format(this.queryOperator, this.fieldName, this._fieldValueString);
		}
		
		public function get conditionDescription(): String{
			if (field.fieldType == FieldDataType.BOOLEAN) {
				if (this.operator.label == "是") {
					return "[" + this.field.text + "]" + " 为 '是'";
				} else {
					return "[" + this.field.text + "]" + " 为 '否'";
				}
			} else {
				return this.field.text 
					+ " " + this.operator.label
					+ " '" + StringUtils.replace(this.fieldValueString, "%", "") + "'";	
			}
		}
	}
}